package com.ruoyi.ro.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ro.domain.goods;
import com.ruoyi.ro.service.IgoodsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 交易所抢购Controller
 * 
 * @author shan
 * @date 2022-05-23
 */
@Controller
@RequestMapping("/xdro/trade")
public class goodsController extends BaseController
{
    private String prefix = "xdro/trade";

    @Autowired
    private IgoodsService goodsService;

    @RequiresPermissions("xdro:trade:view")
    @GetMapping()
    public String trade()
    {
        return prefix + "/trade";
    }

    /**
     * 查询交易所抢购列表
     */
    @RequiresPermissions("xdro:trade:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(goods goods)
    {
        startPage();
        List<goods> list = goodsService.selectgoodsList(goods);
        return getDataTable(list);
    }

    /**
     * 导出交易所抢购列表
     */
    @RequiresPermissions("xdro:trade:export")
    @Log(title = "交易所抢购", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(goods goods)
    {
        List<goods> list = goodsService.selectgoodsList(goods);
        ExcelUtil<goods> util = new ExcelUtil<goods>(goods.class);
        return util.exportExcel(list, "交易所抢购数据");
    }
    @RequiresPermissions("xdro:trade:view")
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<goods> util = new ExcelUtil<>(goods.class);
        return util.importTemplateExcel("交易所抢购");
    }

    @RequiresPermissions("xdro:trade:import")
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<goods> util = new ExcelUtil<>(goods.class);
        List<goods> goodsList = util.importExcel(file.getInputStream());
        int message = goodsService.insertAllGoods(goodsList);
        return AjaxResult.success(message);
    }


    /**
     * 新增交易所抢购
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存交易所抢购
     */
    @RequiresPermissions("xdro:trade:add")
    @Log(title = "交易所抢购", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(goods goods)
    {
        return toAjax(goodsService.insertgoods(goods));
    }

    /**
     * 修改交易所抢购
     */
    @RequiresPermissions("xdro:trade:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        goods goods = goodsService.selectgoodsById(id);
        mmap.put("goods", goods);
        return prefix + "/edit";
    }

    /**
     * 修改保存交易所抢购
     */
    @RequiresPermissions("xdro:trade:edit")
    @Log(title = "交易所抢购", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(goods goods)
    {
        return toAjax(goodsService.updategoods(goods));
    }

    /**
     * 删除交易所抢购
     */
    @RequiresPermissions("xdro:trade:remove")
    @Log(title = "交易所抢购", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(goodsService.deletegoodsByIds(ids));
    }



}
